package Java7_Concurrency_Cookbook.concurrent_custom.custom_atomic_variable;

/**
 * <b>自定义原子对象</b>
 * ParkingCounter主要借助于AtomicInteger的compareAndSet来实现原子操作
 * @author lixiangke
 * @date 2017/11/28
 */
public class Main {
    public static void main(String[] args) throws InterruptedException {
        ParkingCounter counter = new ParkingCounter(5);
        Sensor1 sensor1 = new Sensor1(counter);
        Sensor2 sensor2 = new Sensor2(counter);
        Thread thread1 = new Thread(sensor1);
        Thread thread2 = new Thread(sensor2);
        thread1.start();
        thread2.start();
        thread1.join();
        thread2.join();
        System.out.printf("Main: Number of cars: %d\n", counter.get());
        System.out.printf("Main: End of the program.");
    }
}
